package com.duk.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.duk.model.DaoHang;
import com.duk.model.Dept;
import com.duk.service.TreeService;
import com.duk.util.JacksonJsonUtil;

@Controller
@RequestMapping(value = "/tree")
public class TreeController 
{
	@Resource
	private TreeService treeService;

	@RequestMapping("/DeptTree")
	@ResponseBody
	public String listData(Integer pId) throws IOException
	{

		List<Map<String,Object>> list1=new ArrayList<Map<String,Object>>();
		Map<String,Object> map = new HashMap<String,Object>();
		//{id:"1",pId:"0",name:"逸天教育科技有限公司",uri:"${ctx}/dept/workarea.jsp",open:true}
		map.put("id", 13);
		map.put("pId", 0);
		map.put("name", "逸天教育科技有限公司");
		//map.put("uri", "${ctx}/dept/workarea.jsp");
		map.put("open", "true");
		list1.add(map);
		List<Map<String,Object>> list=treeService.listData(pId);
		list1.addAll(list);
		String tree = JacksonJsonUtil.object2Json(list1);
		return tree;
	}
	@RequestMapping("/fareTree")
	@ResponseBody
	public String fareData(Integer pId) throws IOException
	{
		
		List<Map<String,Object>> list1=new ArrayList<Map<String,Object>>();
		Map<String,Object> map = new HashMap<String,Object>();
		//{id:"1",pId:"0",name:"逸天教育科技有限公司",uri:"${ctx}/dept/workarea.jsp",open:true}
		map.put("id", 13);
		map.put("pId", 0);
		map.put("name", "逸天教育科技有限公司");
		//map.put("uri", "${ctx}/dept/workarea.jsp");
		map.put("open", "true");
		list1.add(map);
		List<Map<String,Object>> list=treeService.fareData(pId);
		list1.addAll(list);
		String tree = JacksonJsonUtil.object2Json(list1);
		return tree;
	}
	@RequestMapping("/getDeptData")
	@ResponseBody
	public String getDeptData(Integer id,HttpServletRequest req,HttpServletResponse res) throws IOException
	{
		List<DaoHang> list=treeService.getDeptData(id);
		req.getSession().setAttribute("list", list);
		return "true";
	}
	@RequestMapping("/getFareData")
	@ResponseBody
	public String getFareData(Integer id,HttpServletRequest req,HttpServletResponse res) throws IOException
	{
		List<DaoHang> list=treeService.getFareData(id);
		req.getSession().setAttribute("list", list);
		return "true";
	}

}
